package com.credithc.fastdfs.api.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.credithc.fastdfs.api.web.BaseController;
import com.credithc.fastdfs.api.web.DownloadCtrl;
import com.credithc.fastdfs.util.PathUtil;

/**
 * @ClassName: FileUtil
 * @Description: 文件操作
 * @author zhaoc
 * @date 2015年5月14日
 * @time 下午1:36:09
 */
public class FileUtil {
	private static final Logger log = LoggerFactory.getLogger(FileUtil.class);

	// public static String ZOOM_SEP = "";//缩略图分隔符
	// public static String CUT_SEP = "";//裁剪分隔符
	// public static String CUT_COORD = "";//裁剪坐标分隔符
	// static {
	// Properties props = new Properties();
	// try {
	// File file = new File(PathUtil.getClassPath() + "separator.properties");
	// InputStream in = new FileInputStream(file);
	// props.load(in);
	// } catch (FileNotFoundException e) {
	// System.err.println("找不到配置文件photoConfig.properties！！");
	// } catch (IOException e) {
	// System.err.println("读取配置文件photoConfig.properties错误！！");
	// e.printStackTrace();
	// }
	// ZOOM_SEP = (String) props.get("zoom.sep");
	// CUT_SEP = (String) props.get("cut.sep");
	// CUT_COORD = (String) props.get("cut.coord");
	// }
	/**
	 * @Title: copyFile
	 * @Description: 文件拷贝
	 * @param
	 * @return File
	 * @throws
	 */
	public static File copyFile(InputStream in, String path) throws IOException {
		File f = new File(path);
		if(!f.getParentFile().exists()){
			f.getParentFile().mkdirs();
		}
		FileOutputStream fs = new FileOutputStream(f);
		byte[] buffer = new byte[1024 * 1024];
		int byteread = 0;
		while ((byteread = in.read(buffer)) != -1) {
			fs.write(buffer, 0, byteread);
			fs.flush();
		}
		fs.close();
		in.close();
		return f;
	}

	public static void main(String[] args) {
		log.info(System.currentTimeMillis() + "");
	}
}
